package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysNovelBook;
import com.ruoyi.system.mapper.SysNovelBookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysNovelCollectionMapper;
import com.ruoyi.system.domain.SysNovelCollection;
import com.ruoyi.system.service.ISysNovelCollectionService;

/**
 * 收藏Service业务层处理
 *
 * @author lcn
 * @date 2022-11-15
 */
@Service
public class SysNovelCollectionServiceImpl implements ISysNovelCollectionService {
    @Autowired
    private SysNovelCollectionMapper sysNovelCollectionMapper;

    @Autowired
    private SysNovelBookMapper sysNovelBookMapper;

    /**
     * 查询收藏
     *
     * @param id 收藏主键
     * @return 收藏
     */
    @Override
    public SysNovelCollection selectSysNovelCollectionById(Long id) {
        SysNovelCollection sysNovelCollection = sysNovelCollectionMapper.selectSysNovelCollectionById(id);
        sysNovelCollection.setBookName(sysNovelBookMapper.selectSysNovelBookById(sysNovelCollection.getBookId()).getBookName());
        return sysNovelCollection;
    }

    /**
     * 查询收藏列表
     *
     * @param sysNovelCollection 收藏
     * @return 收藏
     */
    @Override
    public List<SysNovelCollection> selectSysNovelCollectionList(SysNovelCollection sysNovelCollection) {
        List<SysNovelCollection> list = sysNovelCollectionMapper.selectSysNovelCollectionList(sysNovelCollection);
        for (SysNovelCollection novelCollection :list){
            SysNovelBook book = sysNovelBookMapper.selectSysNovelBookById(novelCollection.getId());
            if (book != null){
                novelCollection.setBookName(book.getBookName());
            }
        }
        return list;
    }

    /**
     * 新增收藏
     *
     * @param sysNovelCollection 收藏
     * @return 结果
     */
    @Override
    public int insertSysNovelCollection(SysNovelCollection sysNovelCollection) {
        sysNovelCollection.setCreateTime(DateUtils.getNowDate());
        return sysNovelCollectionMapper.insertSysNovelCollection(sysNovelCollection);
    }

    /**
     * 修改收藏
     *
     * @param sysNovelCollection 收藏
     * @return 结果
     */
    @Override
    public int updateSysNovelCollection(SysNovelCollection sysNovelCollection) {
        sysNovelCollection.setUpdateTime(DateUtils.getNowDate());
        return sysNovelCollectionMapper.updateSysNovelCollection(sysNovelCollection);
    }

    /**
     * 批量删除收藏
     *
     * @param ids 需要删除的收藏主键
     * @return 结果
     */
    @Override
    public int deleteSysNovelCollectionByIds(Long[] ids) {
        return sysNovelCollectionMapper.deleteSysNovelCollectionByIds(ids);
    }

    /**
     * 删除收藏信息
     *
     * @param id 收藏主键
     * @return 结果
     */
    @Override
    public int deleteSysNovelCollectionById(Long id) {
        return sysNovelCollectionMapper.deleteSysNovelCollectionById(id);
    }
}
